/**
 * Runs all 'File' object API tests in Host Object JSFile.class
 */


module.id = "file_tests";


exports.run = function() {
	doInstantiationTest();
	doWriteTests();
	doReadTests();
	doAppendTests();
	doReadTests();
	// doDeleteTests();
};


Error.prototype.containsMessage = function(str) {
	return (this.message.indexOf(str) > -1);
};


var p = Console.write;
var testfile;
var testString = "Testing File read\nand write API!";


function doInstantiationTest() {
	testfile = new File("testfile.txt");
	// testfile.create();
	p(testfile.toSource());
};


function doWriteTests() {
	
	p("Writing tests...");
	p("File path is:", testfile.path);
	p("\n");
	
	testfile.write(testString, "and this is also from write()", 42924, "AND THIS\n\n\tAND THIS", "\nEnd write()");
	doReadTests();
	testfile.write("To a new beginning!!!!\n", "This has hopefully overwritten everything!\n", "in the file!");
	doReadTests();
	// var write = testfile.write;
	// var wt = require('modules/tools/tester');
	// wt.verbose(true);
// 	
	// wt.add(write, [], fileNotValidAssertion);
// 	
	// wt.run();
	
};


function doReadTests() {
	
	p("Reading tests...");
	p("File path is --->", testfile.path);
	p("\n");
	
	var result = testfile.read();
	
	p("\n");
	p("\nResult toString() is\n", result);
	p("\nResult toSource() is\n", result.toSource());
	
	// var read = testfile.read;
	// var rt = require('modules/tools/tester');
	// rt.verbose(true);
// 	
	// rt.add(read, [], noArgAssertion);
// 	
	// rt.run();
};


function doAppendTests() {
	p("Append tests...");
	p("File path is:", testfile.path);
	p("\n");
	testfile.append("\n AND THISSSSSSSSSSS was append()'ed");
	testfile.append("\n\t\tas was this!\n\t\t\tand this!\n\t");
	testfile.append(248428249, 82482, "\n", 2834);
	testfile.append("\nending append() method call now");
	testfile.append("\nTHE END!");
};


function fileNotValidAssertion(result) {
	return ((result instanceof Error) && (result.containsMessage("not a valid file")));
};


function fileOutOfBoundsAssertion(result) {
	return ((result instanceof Error) && (result.containsMessage("File must be within the local application folder")));
};


// function noArgAssertion(result) {
	// return ((result instanceof Error) && (result.containsMessage("At least one parameter is required")));
// };
// 
// function firstArgStringAssertion(result) {
	// return ((result instanceof Error) && (result.containsMessage("First argument provided must be a String")));
// };
// 
// function secondArgStringAssertion(result) {
	// return ((result instanceof Error) && (result.containsMessage("Second argument provided must be a String")));
// };
// 

